/*
 * @Author: LiYu
 * @Date: 2022-04-03 20:43:16
 * @LastEditors: LiYu
 * @LastEditTime: 2022-04-03 23:02:15
 * @Description: 
 */
import { STAGE_W, SNAKE_W } from '../constants';

class Food {

  element: HTMLElement;

  constructor() {
    this.element = document.querySelector('.food')!;
  }

  get x() {
    return this.element.offsetLeft;
  }

  get y() {
    return this.element.offsetTop;
  }

  change () {
    const blocks = Math.floor(STAGE_W / SNAKE_W) - 1;
    const top = Math.round(Math.random() * blocks) * SNAKE_W;
    const left = Math.round(Math.random() * blocks) * SNAKE_W;

    this.element.style.top = `${top}px`;
    this.element.style.left = `${left}px`;
  }

}

export default Food;